<template>
  <el-cascader
    :value="value"
    size="mini"
    :options="options"
    :props="{label:'name',value:'id'}"
    @change="handleChange"
  />
</template>

<script>
import { getDepartments } from '@/api/employee'
import { transList2TreeData } from '@/utils'

export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      value2: [], // 是个数组  收集选中的值(包含父级)
      options: [
        /*  {
          id: 1,
          name: '指南',
          children: [
            { name: '指南1', id: 2 },
            { name: '指南2', id: 3, children: [{ name: '指南2-1', id: 4 }] }
          ]
        } */
      ]
    }
  },
  created() {
    this.getDepts()
  },
  methods: {
    async getDepts() {
      const res = await getDepartments()
      // console.log(res)
      this.options = transList2TreeData(res, 0)
    },
    async handleChange(val) {
      // console.log(val)
      this.$emit('input', val[val.length - 1])
    }
  }
}
</script>

<style></style>
